package com.lcy.demo.taxi.utils

import org.apache.commons.codec.binary.Base64
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.nio.charset.Charset
import java.util.zip.GZIPInputStream

/**
 * @author loucy
 */
object Decoder {
    @JvmStatic fun decode(str:String):String{
        val bytes = Base64.decodeBase64(str)
        return String(uncompress(bytes))
    }

    @JvmStatic fun uncompress(bytes:ByteArray):ByteArray{
        val outputStream = ByteArrayOutputStream();
        val inputStream = ByteArrayInputStream(bytes)
        val zip = GZIPInputStream(inputStream)
        val read = ByteArray(100)
        var size =zip.read(read,0,100)
        while (size != -1){
            outputStream.write(read,0,size)
            size = zip.read(read,0,100)
        }
        return outputStream.toByteArray()
    }
}

fun main(args: Array<String>) {
    val str = Decoder.decode("H4sIAAAAAAAEAI2RQWuDMBzF74V+B/E8TaLUqLdREAZjk9b1OkIMmk1NiHGsG/vuM1prutMgSN4vj+S9v9/bjeO4z6pk6qF0UwfereBpaEfiIgzjEEGchEEUJzBIIuzOrpz0PesqpoxtYbXo2Ki7oWlmkvGG5UTXxlRrLVMAiOQ+lZ/9G/3yqWjTGEIIPgSnDJzM98CoUCUIIMIgBiECaNp7MPZC5KHI2yXeDr+aPH4rw8vTB1LyoV9LPBJthL/IrrJlLnquueis7FPr4ixN/sBCR030dDGa4V4xolnBW2N012QOwimEKVzm8yLLf/lO3Br9kc2xZ3VPKZP6GuBCC/LO/rSb0G1Dg6yW6x8xB0uqcfLIm5ZjIpl1SZU1pFqfzJRo91yfby8SFtpufn4BJZUZ+04CAAA=")
    println(str)
}